package com.xci.core.base;


import com.xci.core.helper.WebHelper;
import com.xci.core.internal.Sys;
import com.xci.sys.entity.SysUser;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Api控制器基类
 * @author 吕艳阳
 */
public abstract class BaseController {
    /**
     * 获取request
     */
    protected HttpServletRequest getRequest() {
        return WebHelper.getRequest();
    }

    /**
     * 获取response
     */
    protected HttpServletResponse getResponse() {
        return WebHelper.getResponse();
    }

    /**
     * 获取session
     */
    protected HttpSession getSession() {
        return WebHelper.getSession();
    }

    /**
     * 获取当前操作用户
     */
    protected SysUser getCurrentUser() {
        return Sys.me().getCurrentUser();
    }

    /**
     * 获取用户对象
     * @param userId 用户主键
     */
    protected SysUser getUser(String userId) {
        return Sys.me().getUser(userId);
    }

    /**
     * 设置实体用户字段值
     * @param entity 实体对象
     * @param created 是否新建
     */
    public void setUserInfo(Object entity, boolean created) {
        Sys.me().setUserInfo(entity, created);
    }

    /**
     * 设置实体用户字段值
     * @param entity 实体对象
     */
    protected void setCreateUserInfo(Object entity) {
        Sys.me().setUserInfo(entity, true);
    }

    /**
     * 设置实体用户字段值
     * @param entity 实体对象
     */
    protected void setUpdateUserInfo(Object entity) {
        Sys.me().setUserInfo(entity, false);
    }

    /**
     * 设置实体用户字段值
     * @param entity 实体对象
     */
    protected void setOperateUserInfo(Object entity) {
        Sys.me().setUserInfo(entity,false);
    }
}